package com.hingstd.lastwork.controllers;

import com.hingstd.lastwork.dao.AttendanceRepository;
import com.hingstd.lastwork.entities.Attendance;
import com.hingstd.lastwork.services.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("attendances")
public class AttendanceController {

    @Autowired
    AttendanceService attendanceService;

    @GetMapping("/new")
    public String displayAttendanceForm(Model model){

        Attendance aAttendance = new Attendance();
        model.addAttribute("attendance", aAttendance);
        return "new-attendance";
    }

    @PostMapping("/save")
    public String createAttendance(Model model, Attendance attendance){
        //处理保存数据库
        attendanceService.save(attendance);

        return "redirect:/attendances/new";
    }
}
